package com.egao.orderB.service.impl;

import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.damon.utils.Utils;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.entity.User;
import com.egao.orderB.biz.BillOceanApplyBiz;
import com.egao.orderB.entity.BillOceanApply;
import com.egao.orderB.service.BillOceanApplyService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

//import com.egao.orderB.mapper.BillOceanApplyMapper;
//import javax.transaction.Transactional;

/**
 * 拖车海运报关关联表服务实现类
 * @author : Doman
 * @date : 2021-09-14 14:07:15
 * @version ：1.0
 */
@Service
public class BillOceanApplyServiceImpl /*extends ServiceImpl<BillOceanApplyMapper, BillOceanApply> */implements BillOceanApplyService {

	@Autowired
	private BillOceanApplyBiz billOceanApplyBiz;

  @Override
  public JsonResult list(PageResult2<T> page, BillOceanApply billOceanApply, User loginUser)  throws Exception{
      return billOceanApplyBiz.list(page,billOceanApply,loginUser);
  }

  @Override
  public JsonResult list(BillOceanApply billOceanApply, User loginUser) {
      return JsonResult.ok().setData(billOceanApplyBiz.list(billOceanApply,loginUser));
  }

  @Override
  public JsonResult setTriAngle(BillOceanApply billOceanApply, User loginUser) {
    BillOceanApply triangle = null;
    try {
      BillOceanApply triangle2 = new BillOceanApply();
      if (billOceanApply.getKeywords().equals("bill")) {
        triangle2.setBillId(billOceanApply.getBillId());
      } else if (billOceanApply.getKeywords().equals("ocean")) {
        triangle2.setOceanId(billOceanApply.getOceanId());
      } else {
        triangle2.setApplyId(billOceanApply.getApplyId());
      }
      triangle = billOceanApplyBiz.getTriangleById(triangle2);
      if (Utils.isNotEmpty(billOceanApply.getBillId())) {
        triangle.setBillId(billOceanApply.getBillId());
      }
      if (Utils.isNotEmpty(billOceanApply.getOceanId())) {
        triangle.setOceanId(billOceanApply.getOceanId());
      }
      if (Utils.isNotEmpty(billOceanApply.getApplyId())) {
        triangle.setApplyId(billOceanApply.getApplyId());
      }
      billOceanApplyBiz.update(triangle, loginUser);
    }catch (Exception e) {
      billOceanApplyBiz.save(billOceanApply, loginUser);
    }
    return JsonResult.ok().setData(billOceanApplyBiz.setTriAngle(billOceanApply));
  }

  @Override
  public JsonResult getTriangleById(BillOceanApply billOceanApply) {
      return JsonResult.ok().setData(billOceanApplyBiz.getTriangleById(billOceanApply));
  }

  @Override
  public JsonResult getById(BillOceanApply billOceanApply) {
      return JsonResult.ok().setData(billOceanApplyBiz.getById(billOceanApply));
  }

  @Transactional
  @Override
  public JsonResult save(BillOceanApply billOceanApply, User loginUser) {
      if (billOceanApplyBiz.save(billOceanApply, loginUser)) {
          return JsonResult.ok("添加成功");
      }
      return JsonResult.error("添加失败");
  }

  @Transactional
  @Override
  public JsonResult update(BillOceanApply billOceanApply, User loginUser) {
      if (billOceanApplyBiz.update(billOceanApply, loginUser)) {
          return JsonResult.ok("修改成功");
      }
      return JsonResult.error("修改失败");
  }

  @Transactional
  @Override
  public JsonResult remove(BillOceanApply billOceanApply, User loginUser) {
      if (billOceanApplyBiz.remove(billOceanApply, loginUser)) {
          return JsonResult.ok("删除成功");
      }
      return JsonResult.error("删除失败");
  }

}
